export default {
	post(url,data, fun) {
		let token=uni.getStorageSync("token");
		uni.request({
			"url": url,
			"method": "POST",
			"header": {
				token: token
			},
			"data": data,
			success: function(resp) {
				if (resp.statusCode == 401) {
					uni.redirectTo({
						url: "/pages/login/login.vue"
					})
				} else if (resp.statusCode == 200 && resp.data.code == 200) {
					let data = resp.data
					if (data.hasOwnProperty("token")) {
						let token = data.token
						uni.setStorageSync("token", token)
					}
					fun(resp)
				} else {
					uni.showToast({
						icon: "none",
						title: resp.data
					})
				}
			},
		})
	},
	get(url,data, fun) {
		let token=uni.getStorageSync("token");
		uni.request({
			"url": url,
			"method": "GET",
			"header": {
				token: token
			},
			"data": data,
			success: function(resp) {
				if (resp.statusCode == 401) {
					uni.redirectTo({
						url: "/pages/login/login.vue"
					})
				} else if (resp.statusCode == 200) {
					let data = resp.data
					if (data.hasOwnProperty("token")) {
						let token = data.token
						uni.setStorageSync("token", token)
					}
					fun(resp)
				} else {
					uni.showToast({
						icon: "none",
						title: resp.data
					})
				}
			},
		})
	}
}	